package net.zjitc.controller;

import net.zjitc.pojo.User;
import net.zjitc.service.UserService;
import net.zjitc.service.impl.UserServiceImpl;
import net.zjitc.utils.dispacher.URLMapping;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * Created by tt on 2017/11/18.
 */
public class UserCon {
    UserService service=new UserServiceImpl();
    //管理员的用户界面显示
    @URLMapping(url = "/adminUser")
    public String userList(HttpServletRequest request, HttpServletResponse response){
        List<User> list=service.findUserList();
        request.setAttribute("list",list);
        return "/admin/user/list.jsp";
    }
    //删除
    @URLMapping(url = "/deleteUser")
    public String deleteUser(HttpServletRequest request,HttpServletResponse response){
        User user=new User();
        try {
            BeanUtils.populate(user,request.getParameterMap());
            int count=service.deleteUser(user);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return "Redirect:"+request.getContextPath()+"/adminUser";
    }
}
